﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using VitCode.ObjectResolutionHelper;

namespace VitCode.Castle.Entities
{
    [OrMemo("用户组")]
    public class UserGroup:BaseEntity
    {
        protected string m_Name;
        /// <summary>
        /// 名称
        /// </summary>
        [OrMemo("名称")]
        public virtual string Name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }

        protected string m_TypeName;
        /// <summary>
        /// 类型名称
        /// </summary>
        [OrMemo("类型名称")]
        public virtual string TypeName
        {
            get { return m_TypeName; }
            set{ m_TypeName = value;}
        }

        protected UserGroup m_Parent;
        /// <summary>
        /// 父菜单
        /// </summary>
        [OrMemo("父节点")]
        public virtual UserGroup Parent
        {
            get { return m_Parent; }
            set
            {
                if (value != null && value == this)
                    throw new ArgumentException("不是设置本节点为父节点");
                m_Parent = value;
            }
        }

        /// <summary>
        /// 节点树模型的层次信息
        /// </summary>
        [OrMemo("OrderId")]
        public virtual string OrderId { get;set;}

        /// <summary>
        /// 重写Equals方法
        /// </summary>
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(obj, this))
                return true;
            if (obj == null)
                return false;
            var sObj = obj as UserGroup;
            return sObj != null && (sObj.Id == Id || (sObj.Name == m_Name));
        }

        /// <summary>
        /// 重写GetHashCode方法
        /// </summary>
        public override int GetHashCode()
        {
            int hash = 55;
            hash = 27 * hash * Id.GetHashCode();
            return hash;
        }
    }
}
